﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;


public partial class admin_view_buy : System.Web.UI.Page
{
    string ss;
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["p_id"] = Request.QueryString["id"].ToString();
        BindGridviewData();
        Label67.Text = Session["p_id"].ToString();


        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        ss = Request.QueryString["id"].ToString (); 
        Label1.Text = Session["email"].ToString();

        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Request.QueryString["id"].ToString(); ; 
            // Image1 .ImageUrl ="property.ashx?p_id=" + str.ToString();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM properties where p_id='" + Request.QueryString["id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {
                //Client Details 
                txtclient_fullname1.Text = dr[7].ToString();
                txtclient_fullname2.Text = dr[8].ToString();
                lblssn.Text = dr[9].ToString();
                lblphone.Text = dr[10].ToString();
         

                //End Client Details 

                //Client Address
                lblsteet.Text = dr[13].ToString();
                lblhouse.Text = dr[11].ToString();
               
                lblcity.Text = dr[12].ToString();
                Label141.Text = dr[14].ToString();
                Label142.Text = dr[15].ToString();
                lblcount.Text = dr[19].ToString();
                lblzip.Text = dr[18].ToString();


                Label97.Text = dr[21].ToString();
                Label98.Text = dr[22].ToString();
                Label99.Text = dr[23].ToString();
                Label100.Text = dr[24].ToString();
                Label101.Text = dr[25].ToString();


                Label143.Text = dr[29].ToString();
                Label144.Text = dr[31].ToString();
                Label145.Text = dr[32].ToString();
                Label146.Text = dr[33].ToString();
                Label147.Text = dr[34].ToString();
                Label148.Text = dr[35].ToString();
                Label149.Text = dr[36].ToString();
                Label150.Text = dr[37].ToString();
                Label151.Text = dr[38].ToString();
                Label152.Text = dr[39].ToString();


                Label153.Text = dr[40].ToString();
                Label154.Text = dr[41].ToString();
                Label155.Text = dr[42].ToString();
                Label156.Text = dr[43].ToString();
                Label157.Text = dr[44].ToString();
                Label158.Text = dr[45].ToString();
                Label159.Text = dr[46].ToString();
                Label160.Text = dr[47].ToString();
                Label161.Text = dr[48].ToString();
                Label162.Text = dr[49].ToString();
                Label163.Text = dr[52].ToString();
                Label164.Text = dr[53].ToString();
                Label165.Text = dr[54].ToString();
                Label166.Text = dr[55].ToString();
                Label167.Text = dr[56].ToString();
                Label168.Text = dr[57].ToString();
                Label169.Text = dr[58].ToString();
                Label170.Text = dr[64].ToString();
                Label171.Text = dr[65].ToString();
                Label172.Text = dr[66].ToString();
                Label173.Text = dr[67].ToString();
                Label174.Text = dr[68].ToString();
                Label175.Text = dr[69].ToString();
                Label176.Text = dr[70].ToString();
                Label177.Text = dr[71].ToString();
                Label178.Text = dr[72].ToString();
                Label179.Text = dr[73].ToString();
                Label180.Text = dr[74].ToString();
                Label181.Text = dr[75].ToString();
                Label182.Text = dr[76].ToString();
                Label183.Text = dr[77].ToString();
                Label184.Text = dr[80].ToString();
                Label185.Text = dr[81].ToString();
                Label186.Text = dr[82].ToString();
                Label187.Text = dr[83].ToString();
                //Label188.Text = dr[84].ToString();
                Label189.Text = dr[85].ToString();
                Label190.Text = dr[86].ToString();
                Label191.Text = dr[87].ToString();
                Label192.Text = dr[88].ToString();
                Label193.Text = dr[89].ToString();
                Label194.Text = dr[90].ToString();
                Label195.Text = dr[92].ToString();
                Label196.Text = dr[93].ToString();
                Label197.Text = dr[94].ToString();
                Label198.Text = dr[95].ToString();
                Label199.Text = dr[96].ToString();
                Label200.Text = dr[97].ToString();
                Label201.Text = dr[98].ToString();



                if (Label153.Text == "שדה למילוי עצמי")
                {
                    Label153.Text = "-";
                }

                else
                {
                    Label153.Text = dr[40].ToString();
                }

//////////////////////////////////////////////////////////////////////

             if (Label159.Text == "שדה למילוי עצמי")
             {
                 Label159.Text = "-";
             }

             else
             {
                 Label159.Text = dr[46].ToString();
             }
//////////////////////////////////////////////////////////////////////


             if (Label161.Text == "שדה למילוי עצמי")
             {
                 Label161.Text = "-";
             }

             else
             {
                 Label161.Text = dr[48].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label144.Text == "שדה למילוי עצמי")
             {
                 Label144.Text = "-";
             }

             else
             {
                 Label144.Text = dr[31].ToString();
             }
//////////////////////////////////////////////////////////////////////
            

             if (Label148.Text == "שדה למילוי עצמי")
             {
                 Label148.Text = "-";
             }

             else
             {
                 Label148.Text = dr[35].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label151.Text == "שדה למילוי עצמי")
             {
                 Label151.Text = "-";
             }

             else
             {
                 Label151.Text = dr[38].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label155.Text == "שדה למילוי עצמי")
             {
                 Label155.Text = "-";
             }

             else
             {
                 Label155.Text = dr[42].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label157.Text == "שדה למילוי עצמי")
             {
                 Label157.Text = "-";
             }

             else
             {
                 Label157.Text = dr[44].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label163.Text == "שדה למילוי עצמי")
             {
                 Label163.Text = "-";
             }

             else
             {
                 Label163.Text = dr[52].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label165.Text == "שדה למילוי עצמי")
             {
                 Label165.Text = "-";
             }

             else
             {
                 Label165.Text = dr[54].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label171.Text == "שדה למילוי עצמי")
             {
                 Label171.Text = "-";
             }

             else
             {
                 Label171.Text = dr[65].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label174.Text == "שדה למילוי עצמי")
             {
                 Label174.Text = "-";
             }

             else
             {
                 Label174.Text = dr[68].ToString();
             }
//////////////////////////////////////////////////////////////////////
             if (Label176.Text == "שדה למילוי עצמי")
             {
                 Label176.Text = "-";
             }

             else
             {
                 Label176.Text = dr[70].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label178.Text == "שדה למילוי עצמי")
             {
                 Label178.Text = "-";
             }

             else
             {
                 Label178.Text = dr[72].ToString();
             }
//////////////////////////////////////////////////////////////////////


             if (Label182.Text == "שדה למילוי עצמי")
             {
                 Label182.Text = "-";
             }

             else
             {
                 Label182.Text = dr[76].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label186.Text == "שדה למילוי עצמי")
             {
                 Label186.Text = "-";
             }

             else
             {
                 Label186.Text = dr[82].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label190.Text == "שדה למילוי עצמי")
             {
                 Label190.Text = "-";
             }

             else
             {
                 Label190.Text = dr[86].ToString();
             }
//////////////////////////////////////////////////////////////////////

             if (Label192.Text == "שדה למילוי עצמי")
             {
                 Label192.Text = "-";
             }

             else
             {
                 Label192.Text = dr[88].ToString();
             }
//////////////////////////////////////////////////////////////////////

            }


            dr.Close();
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {




        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView2.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select p_id from properties where p_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("view-task.aspx");
            // con.Close();


        }
    }


    protected void Save_Click(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {


        //  string pageurl="Default.aspx?Id=6&RollNo=15";

        //Response.Write(<script> window.open( ‘"+pageurl+"’,'_blank' ); </script>);
        //Response.End();
    }

    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    private void BindGridviewData()
    {
        SqlConnection con = null;
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select * from files where id='" + Request.QueryString["id"] + "'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        gvDetails.DataSource = ds;
        gvDetails.DataBind();

        con.Close();
    }
    protected void lnkDownload_Click(object sender, EventArgs e)
    {
        LinkButton lnkbtn = sender as LinkButton;
        GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        string file_path = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Response.ContentType = "image/jpg";
        Response.AddHeader("Content-Disposition", "attachment;filename=\"" + file_path + "\"");
        Response.TransmitFile(Server.MapPath(file_path));
        Response.End();
    }

}